{template nheader.html}
<script type="text/javascript">
	$(function(){
		// 排序操作
		$('.dr_table th').click(function(e) {
			var _class = $(this).attr("class");
			if (_class == undefined) return;
			var _name = $(this).attr("name");
			var _order = '';
			if (_class == "sorting") {
				_order = 'desc';
			} else if (_class == "sorting_desc") {
				_order = 'asc';
			} else {
				_order = 'desc';
			}
			var url = "{dr_member_order($moreurl)}&order="+_name+" "+_order;
			location.href=url;
		});
	});
	function dr_update() {
		$("#action").val('update');
		var _data = $("#myform").serialize();
		var _url = window.location.href;
		if ((_data.split('ids')).length-1 <= 0) {
			dr_tips("到底排序谁？您还没有选择呢", 2);
			return true;
		}
		$.ajax({type: "POST",dataType:"json", url: _url, data: _data,
			success: function(data) {
				if (data.status == 1) {
					dr_tips(data.code, 3, 1);
					$.post("{SITE_URL}index.php?s={MOD_DIR}&c=show&m=create_html&id={$cid}", {}, function(){});
					setTimeout('window.location.reload(true)', 3000);
				} else {
					dr_tips(data.code, 3, 2);
					return true;
				}

			},
			error: function(HttpRequest, ajaxOptions, thrownError) {
				alert(thrownError + "\r\n" + HttpRequest.statusText + "\r\n" + HttpRequest.responseText);
			}
		});
		return false;
	}
	function dr_delete(id) {

		var d = top.dialog({
			title: lang["tips"],
			fixed: true,
			content: '<img src="/statics/js/skins/icons/question.png"> <font color=red><b>你确认要删除吗？</b></font>',
			okValue: lang['ok'],
			ok: function () {
				$.ajax({type: "POST",dataType:"json", url: "{dr_member_url(MOD_DIR.'/extend/del', array('cid'=>$cid))}",data: {id:id}, success: function(data) {
					if (data.status == 1) {
						dr_tips(data.code, 3, 1);
						$("#dr_row_"+id).hide();
					} else {
						dr_tips(data.code, 3, 0);
					}
					art.dialog.close();
					return false;
				},
					error: function(HttpRequest, ajaxOptions, thrownError) {
						alert(thrownError + "\r\n" + HttpRequest.statusText + "\r\n" + HttpRequest.responseText);
					}
				});
				return true
			},
			cancelValue: lang['cancel'],
			cancel: function () {}
		});
		d.show();
	}
	function dr_status(id, v) {
		var title = "";
		if (v == 9) {
			title = "<font color=red><b>{fc_lang('您确定要将它关闭吗？')}</b></font>";
		} else {
			title = "<font color=blue><b>{fc_lang('您确定要将它开启吗？')}</b></font>";
		}
		var d = top.dialog({
			title: lang["tips"],
			fixed: true,
			content: '<img src="/statics/js/skins/icons/question.png"> '+title,
			okValue: lang['ok'],
			ok: function () {
				// 将表单数据ajax提交验证
				$.ajax({type: "POST",dataType:"json", url: "{dr_member_url(MOD_DIR.'/extend/status')}&id="+id+"&cid={$cid}", success: function(data) {
					//验证成功
					if (data.status == 1) {
						dr_tips(data.code, 3, 1);
						if (data.id) {
							$.ajax({
								type: "POST",
								dataType:"jsonp",
								url:"{SITE_URL}index.php?s={MOD_DIR}&c=show&m=create_html&id={$cid}",
								success: function(data) { },
								error: function(HttpRequest, ajaxOptions, thrownError) { }
							});
							$.ajax({
								type: "POST",
								dataType:"jsonp",
								url:"{SITE_URL}index.php?s={MOD_DIR}&c=show&m=create_list_html&id="+data.id,
								success: function(data) { },
								error: function(HttpRequest, ajaxOptions, thrownError) { }
							});
						}
						setTimeout('window.location.reload(true)', 3000); // 刷新页
					} else {
						dr_tips(data.code);
					}
				},
					error: function(HttpRequest, ajaxOptions, thrownError) {
						alert(HttpRequest.responseText);
					}
				});
				return true
			},
			cancelValue: lang['cancel'],
			cancel: function () {}
		});
		d.show();
	}
</script>

<div class="row">
	<div class="col-md-12">

		<div class="portlet-body">
			<div class="table-toolbar">
				<form method="get" action="">
					<input name="s" type="hidden" value="{MOD_DIR}" />
					<input name="c" type="hidden" value="extend" />
					<input name="m" type="hidden" value="index" />
					<input name="cid" type="hidden" value="{$cid}" />
					<input id="dr_order" name="order" type="hidden" value="{$get.order}" />
					<div class="row">
						<div class="col-md-6">
							<label>
								<div class="btn-group">
									<a class="btn green" href="{dr_member_url(MOD_DIR.'/extend/add', array('cid'=>$cid))}"> {fc_lang('发布')}
										<i class="fa fa-plus"></i>
									</a>
								</div>
							</label>
						</div>
						<div class="col-md-4 col-md-offset-2">
							<label class="text-right">
								<div class="input-group">
									<input type="text" class="form-control" id="dr_keywords" name="kw" placeholder="关键字查询" value="{$kw}">
									<span class="input-group-btn">
										<button class="btn green mysubmit" type="submit"><i class="fa fa-search"></i> 搜索</button>
									</span>
								</div>
							</label>
						</div>

					</div>
				</form>
			</div>

			<form action="" method="post" name="myform" id="myform">
				<input name="action" id="action" type="hidden" value="" />
				<div class="table-responsive">
					<table class="dr_table table dataTable">
						<thead>
						<tr>
							<th style="width:20px;" class="algin_r">&nbsp;</th>
							<th class="{ns_sorting('displayorder')}" name="displayorder">排序</th>
							<th class="{ns_sorting('name')}" name="name">{fc_lang('名称')}</th>
							<th class="{ns_sorting('updatetime')}" name="updatetime">更新时间</th>
							<th class="{ns_sorting('status')}" name="status">状态</th>
							<th></th>
						</tr>
						</thead>
						<tbody id="dr_body">
						{loop $list $t}
						<tr id="dr_row_{$t.id}">
							<td class="" style="padding-top:7px;padding-left:15px"><input type="checkbox" value="{$t.id}" class="dr_select toggle md-check" name="ids[]"></td>
							<td class=""><input class="input-text displayorder" type="text" name="data[{$t.id}][displayorder]" value="{$t.displayorder}" /></td>
							<td class=""><div class="dr_title"><a href="{if $t.status==9}{$t.url}{else}{SITE_URL}index.php?s={MOD_DIR}&c=extend&id={$t.id}{/if}" title="{$t.name}" target="_blank">{dr_keyword_highlight($t.name, $kw)}</a></div></td>
							<td class="">{dr_date($t.updatetime, '', 'red')}</td>
							<td class=" html5">{if $t.status == 9}<a class="btn green btn-xs" href="javascript:dr_status({$t.id}, '{$t.status}');">{fc_lang('正常')}</a>{else}<a class="btn red btn-xs" href="javascript:dr_status({$t.id}, '{$t.status}');">{fc_lang('关闭')}</a>{/if}</td>
							<td class="">
								{if $catrule.edit}<a href="{dr_member_url(MOD_DIR.'/extend/edit', array('cid'=>$cid, 'id'=>$t.id))}" class="btn green btn-xs" ><i class="fa fa-edit"></i> 修改</a>{/if}
								{if $catrule.del}<a href="javascript:;" onclick="dr_delete('{$t.id}')" class="btn red-mint btn-xs" ><i class="fa fa-trash-o"></i> 删除</a>{/if}
							</td>
						</tr>
						{/loop}
						</tbody>
						<tr>
							<td style="padding-top:15px;padding-left:15px"><input class="toggle md-check" ck="0" type="checkbox" onclick="dr_selected2()" id="dr_select" name="dr_select"></td>
							<td colspan="22">
								<div class="row">
									<div class="col-md-1">
										<label>
											<button type="button" class="btn btn-sm btn-success" onClick="dr_update()"><i class="fa fa-refresh"></i> 排序</button>
										</label>
									</div>

									<div class="col-md-5">
										&nbsp;
									</div>
								</div>
							</td>
						</tr>
					</table>
				</div>
			</form>
		</div>


	</div>
</div>

<div class="row">
	<div class="col-md-12 text-center">
		<ul class="pagination">
			{$pages}
			<li><a href="javascript:;">共{$page_total}条</a></li>
		</ul>
	</div>
</div>

{if IS_MOBILE}
<div class="alert alert-info" style="margin-top: 15px">
	左右滑动表格可以查看更多的内容
</div>
{/if}
{template "nfooter.html"}